﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Task3
{
    public class Graph
    {
        internal const int MaxNode = 1024;
        private int[][] childNodes;

        public Graph(int[][] childNodes)
        {
            this.childNodes = childNodes;
        }

        public void TraverseDFSRecursive(int node, bool[] visited)
        {
            if (!visited[node])
            {
                visited[node] = true;
                Console.Write("{0} ", node);
                foreach (int childNode in childNodes[node])
                {
                    TraverseDFSRecursive(childNode, visited);
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Graph g = new Graph(new int[][] {
			new int[] {3, 6}, // successors of vertice 0
			new int[] {2, 3, 4, 5, 6}, // successors of vertice 1
			new int[] {1, 4, 5}, // successors of vertice 2
			new int[] {0, 1, 5}, // successors of vertice 3
			new int[] {1, 2, 6}, // successors of vertice 4
			new int[] {1, 2, 3}, // successors of vertice 5
			new int[] {0, 1, 4}  // successors of vertice 6
		});

            bool[] visited = new bool[Graph.MaxNode];
            g.TraverseDFSRecursive(0, visited);
        }
    }
}
